package com.gdwstudy.exception;

import java.util.Scanner;

/**
 * @author 关道伟
 * @version 1.0
 */
public class Exception02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = 0;
        String res = " ";
        System.out.println("请输入你要转换的字符：");
        while (true) {
            try {
                //当try检测出异常时，出现异常的语句之后的代码将不会再执行
                //而是直接转入catch
                res = scanner.next();
                num = Integer.parseInt(res);
                break;
            } catch (Exception e) {
                System.out.println("你输入的不是数字字符，请重新输入:");
            }

        }
        System.out.println("你输入的是：" + num);
    }
}
